package com.leetcode;

/**
 * 125. 验证回文串
 * 双索引指针
 */
public class Solution125 {

    public boolean isPalindrome(String s) {
        int n = s.length();
        int p = 0;
        int q = n - 1;
        while (p <= q) {
            if (!Character.isLetterOrDigit(s.charAt(p))) {
                p++;
                continue;
            }
            if (!Character.isLetterOrDigit(s.charAt(q))) {
                q--;
                continue;
            }
            if (Character.toLowerCase(s.charAt(p)) != Character.toLowerCase(s.charAt(q))) {
                return false;
            } else {
                p++;
                q--;
            }
        }
        return true;
    }

    public static void main(String[] args) {
//        String s = "A man, a plan, a canal: Panama";
        String s = "0P";
        boolean res = new Solution125().isPalindrome(s);
        System.out.println(res);
    }

}
